package com.example.zte.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListSimpleActivity extends AppCompatActivity {

    //定义名字数组
    private String[] name = {"张三", "王五", "赵六"};
    //定义描述任务数组
    private String[] desc = {"唱歌", "跳舞", "打球"};
    //定义头像数组
    private int[] icon = new int[]{R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        ListView listView =
                (ListView) findViewById(R.id.listview1);

        // 初始化数据
        List<Map<String, Object>> list = new ArrayList<>(0);
        for (int i = 0; i < name.length; i++) {
            Map<String, Object> aa = new HashMap<>();
            aa.put("xx1", name[i]);
            aa.put("xx2", icon[i]);
            aa.put("xx3", desc[i]);
            list.add(aa);
        }
        SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, R.layout.list_item_layout,
                new String[]{"xx1", "xx2", "xx3"},
                new int[]{R.id.name, R.id.icon, R.id.desc});

        //为listview设置adapter
       // listView.a
        listView.setAdapter(simpleAdapter);

    }
}
